let currentServCategId = 0;
/**
 * zmn渠道管理-服务分类
 * 文件命名格式：zmn.模块.表/功能.js
 * @author xiangjunming
 * @since 2019/08/22 18:06
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    form.render(null, "zmn-form");


    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        let data = obj.field;
        let selected = [];
        //获取选中的二级分类
        $("input:checkbox[name='categoryId']:checked").each(function(i){
            let currentValue = $(this).val();
            let categs = currentValue.split("-");
            selected.push({"servCategId":categs[0],"categOneId":categs[1],"categTwoId":categs[2]});
        });
        if(selected.length<1){
            layer.alert("请选择至少一个分类数据");
            return false;
        }
        data.categIds=selected;
        var url = "/showProduct/copyFromProduct.action";
        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json",
            dataType: "json", data: JSON.stringify(data),
            success:function(result) {
                if(result.status == 200) {
                    layer.msg(result.message,{time: 1000},()=>{
                       location.reload();
                    });
                } else {
                    layer.msg(result.message, {"icon": 2});
                }
            },
            error:function(XMLHttpRequest, status, errorThrown){}
        });
        return false;
    });

    //对外暴露的接口
    exports('product_serv_category', {});
});